package com.site.wisdom_construction.controller.healthEpidemicModel;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.healthEpidemicModel.BloodPressureHistoryService;
import com.site.wisdom_construction.util.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/7
 * @Description
 */
@Api(tags = "定位手环血压历史数据接口")
@RestController
@RequestMapping("BloodPressureHistory")
@CrossOrigin
public class BloodPressureHistoryController {
    @Autowired
    private BloodPressureHistoryService bloodPressureHistoryService;

    @ApiOperation(value = "增加定位手环血压历史数据", notes = "测试数据:")
    @PostMapping("/insertBloodPressureHistory")
    public JsonResult insertBloodPressureHistory(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateTime", TimeUtils.getNowTimeS());
        int i = bloodPressureHistoryService.insertBloodPressureHistory(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入定位手环血压历史数据!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入定位手环血压历史数据失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除定位手环血压历史数据", notes = "测试数据:")
    @PostMapping("/deleteBloodPressureHistory")
    public JsonResult deleteBloodPressureHistory(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = bloodPressureHistoryService.deleteBloodPressureHistory(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除定位手环血压历史数据!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除定位手环血压历史数据失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询定位手环血压历史", notes = "测试数据:")
    @PostMapping("/findBloodPressureHistoryByPage")
    public Page findBloodPressureHistoryByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(bloodPressureHistoryService.Total(map));
        page.setItems(bloodPressureHistoryService.findBloodPressureHistoryByPage(map));
        return page;
    }
}
